package com.zz.dubbo.example.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Created by zhouzeng on 2017/8/25.
 */
@Component
public class SpringBeanContextUtil implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext arg0)
            throws BeansException {
        context = arg0;
    }

    public static ApplicationContext getContext(){
        return context;
    }

    public static Object getBean(String beanName) {
        return context.getBean(beanName);
    }

    public static<T> T getBeanByType(Class<T> tClass){
        return context.getBean(tClass);
    }
}
